package com.woniuxy.yuekeuser.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.yuekeuser.controller.Info.CampsiteCommentInfo;
import com.woniuxy.yuekeuser.controller.Info.CommentAndImage;
import com.woniuxy.yuekeuser.info.FileItem;
import com.woniuxy.yuekeuser.model.CampsiteComment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.yuekeuser.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Freedom
 * @since 2020-11-03
 */
public interface CampsiteCommentMapper extends BaseMapper<CampsiteComment> {

    @Insert("insert into campsite_comment(user_id,campsite_id,campsite_comment_content,comment_rating)" +
            " values(#{userId},#{campsiteId},#{commentContent},#{rate})")
    int campsiteComment(CampsiteCommentInfo campsiteCommentInfo);

    @Insert("insert into campsite_comment_images(campsite_comment_id,image_url) value(#{commentId},#{url})")
    void insertCommentImage(@Param("url") String url,@Param("commentId") int commentId);

    @Options(useGeneratedKeys = true,keyProperty = "commentId",keyColumn = "campsite_comment_id")
    @Insert("insert into campsite_comment(user_id,campsite_id,campsite_comment_content,comment_rating)" +
            " values(#{userId},#{campsiteId},#{commentContent},#{rate})")
    int insertComment(CampsiteCommentInfo campsiteCommentInfo);

    @Select("select * from campsite_comment where campsite_id = #{campsiteId}")
    IPage<CommentAndImage> loadCampsiteCommentById(Page<CampsiteComment> page, int campsiteId);

    @Select("select image_url from campsite_comment_images where campsite_comment_id = #{commentId}")
    List<String> commentImage(int commentId);

    @Select("select name from user where user_id = #{userId}")
    String selectNameById(Integer userId);
}
